{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 百度文本纠错\n",
    "准确识别输入文本中出现的拼写错别字及其段落位置信息，并针对性给出正确的建议文本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 7333761494327865942, 'item': {'vec_fragment': [{'ori_frag': '传通', 'begin_pos': 32, 'correct_frag': '传统', 'end_pos': 36}], 'score': 0.348703, 'correct_query': '驴打滚，是东北地区、老北京和天津传统的小吃之一，因其最后制作工序中撒上的黄豆面，犹如老北京郊外野驴撒欢打滚时扬起的阵阵黄土，因此而得名“驴打滚”。'}, 'text': '驴打滚，是东北地区、老北京和天津传通的小吃之一，因其最后制作工序中撒上的黄豆面，犹如老北京郊外野驴撒欢打滚时扬起的阵阵黄土，因此而得名“驴打滚”。'}\n"
     ]
    }
   ],
   "source": [
    "from aip import AipFace,AipBodyAnalysis\n",
    "from IPython.display import Image\n",
    "from IPython.core.display import HTML\n",
    "from aip import AipNlp\n",
    "\"\"\" 你的 APPID AK SK \"\"\"\n",
    "APP_ID = '23575550'\n",
    "API_KEY = 'fr8nHvzt2FtHfvOLeaen7uju'\n",
    "SECRET_KEY = 'Mrfk2PZR2z4AtNWFzDhCvz7AQxNrps0e'\n",
    "client = AipNlp(APP_ID, API_KEY, SECRET_KEY)\n",
    "text = \"驴打滚，是东北地区、老北京和天津传通的小吃之一，因其最后制作工序中撒上的黄豆面，犹如老北京郊外野驴撒欢打滚时扬起的阵阵黄土，因此而得名“驴打滚”。\"\n",
    "\n",
    "\"\"\" 调用文本纠错接口 \"\"\"\n",
    "print(client.ecnet(text))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'正确的句子为：驴打滚，是东北地区、老北京和天津传统的小吃之一，因其最后制作工序中撒上的黄豆面，犹如老北京郊外野驴撒欢打滚时扬起的阵阵黄土，因此而得名“驴打滚”。'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = client.ecnet(text)\n",
    "\"正确的句子为：\" + df['item']['correct_query']"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
